package com;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

import cn.hutool.setting.Setting;

public class ReadProperties {

	public static void main(String[] args) {
		Setting setting = new Setting("D:\\AijunTao\\Desktop\\apppro\\app.properties");
		Setting setting2 = new Setting("D:\\AijunTao\\Desktop\\apppro\\app-20221114.properties");
		
		for (String group : setting.keySet()) {
			String value = setting.get(group);
			if (value.contains("@")) {
				Map<String, String> comMap = createStringMap(value);
				Map<String, String> oldMap = createStringMap(setting2.get(group));
				
				removeCommFromMap(comMap, oldMap);
				if (comMap.size() > 0 || oldMap.size() > 0) {
					System.out.println(group+"==");
					printMap(comMap);
					printMap(oldMap);	
				}
				
			}
		}

	}

	private static void printMap(Map<String, String> comMap) {
		for(String key : comMap.keySet()) {
			System.out.print(key + " , ");
		}
		System.out.println();		
	}

	private static void removeCommFromMap(Map<String, String> comMap, Map<String, String> oldMap) {
		Iterator it = comMap.entrySet().iterator();
		while (it.hasNext()) {
			Map.Entry entry = (Entry) it.next();
			String key = entry.getKey().toString();
			if (oldMap.containsKey(key)) {
				oldMap.remove(key);
				it.remove();
			}
		}
		it = oldMap.entrySet().iterator();
		while (it.hasNext()) {
			Map.Entry entry = (Entry) it.next();
			String key = entry.getKey().toString();
			if (comMap.containsKey(key)) {
				comMap.remove(key);
				it.remove();
			}
		}

	}

	private static Map<String, String> createStringMap(String value) {
		String[] strs = value.split(",");
		Map<String, String> map = new HashMap<>();
		for (String s : strs) {
			map.put(s, s);
		}
		return map;
	}

}
